<?php
/*
Plugin Name: BBGroup
Author:  Kebot
Author URI: http://kebot.me/
Plugin URI: http://kebot.me/group/
Version: 1.0
Description:
Make your BBPress as Group. 
A forum is a Group.
User can Creat/Add

*/

class bbGroup{

  var $uid;

  var $group_id;

/*
 * @var array The Group settings , as chosen by the user
 * store in bb_meta->bb_option->bbgroup_settings
 * 	#version -> plugin version
 *  #can_creat -> can members creat a group?
 *  	value 0 can't creat
 *  	value 1 can creat but need verification
 *  	value 2 can freely creat group
 *  #
 *  
 *  
 */
  var $settings;

/*
 * version of this plugin
 */
  var $version;
  
/*
 * value 0 can't creat
 *  	value 1 can creat but need verification
 *  	value 2 can freely creat group
 */
  var $can_creat;

/*
 * Initializes bbGroup
 * 初始化
 * 
 * 
 */
  function bbGroup(){
	global $bbdb;
	$bbdb->bbgroup = $bbdb->prefix.'bbgroup';
	$this->settings=bb_get_option('bbgroup_settings');
	
	$this->version=$this->settings['version'];
	$this->can_creat=$this->settings['can_creat'];
	
	
	if(!$this->version){
		$this->update();
	}
	$this->uid = bb_get_current_user_info( 'id' );
	
	
}
/*
/* Update database to new version
 * 创建/更新 数据库表
 * @access private
 */
  function update(){
	global $bbdb;
	
	$bbdb->query(
	'CREATE TABLE `'. $bbdb->bbgroup .'` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `forum_id` int(11) NOT NULL,
  `user_id` bigint(20) NOT NULL,
  `group_status` tinyint(1) NOT NULL,
  `join_time` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1'
);

	$this->version='1.0';
	$this->settings['version']='1.0';
	
	bb_update_option( 'bbgroup_settings', $this->settings );
	}

/*
 * 
 */
  function join_group($uid,$group_id){
		global $wpdb;
		
		
		
		
	}
/*
 * apply to group.
 * success: store Info into usermate->bbgroup_applys
 */	
  function apply_group(){
  	$global->db;
  	if(1){
  		if($this->can_creat==0){
  			return;
  		}elseif($this->can_creat==1){
  			
  		}
  	}
  	
  }
/*
 * 
 * 
 */	

  function creat_group(){
  	
  }
	
}




$GLOBALS['bbgroup'] = new bbGroup;


/*
 * Show This Group
 */





?>